package util

import (
	"time"
)

const shortForm = "2006-01-02"

// JudgeAgeIsGreaterThan18ByStrDateOfBirth 根据生日判断年龄是大于18岁 dateOfBirth格式为："1998-12-22"
func JudgeAgeIsGreaterThan18ByStrDateOfBirth(date string) (bool, error) {
	d, err := time.Parse(shortForm, date)
	if err != nil {
		return false, err
	}
	dateOfBirthAdd18 := d.AddDate(18, 0, 0).Unix()
	now := time.Now().Unix()
	if now > dateOfBirthAdd18 {
		return true, nil
	}
	return false, nil
}
